<?php
/**
 * about business basic message
 * edit by kim
 */
class b2c_ctl_admin_operator_list extends desktop_controller{
	function index(){
		$this->finder('b2c_mdl_business_goodscollection',array(
			'title'=>app::get('b2c')->_('集货单管理'),
			'allow_detail_popup'=>true,
			'use_buildin_recycle'=>false,
			'use_view_tab'=>true
		));
	}

    //获取有效订单号 by yyj 2016/4/25
    public function get_bo_ids(){
        $b_order = $this->app->model('business_orders');
        $ids = $b_order->getList('childOrder_id',array('order_status|noequal'=>'dead','status|noequal'=>'0'));
        $order_ids = array();
        foreach($ids as $key => $id){
            $order_ids[] = $id['childOrder_id'];
        }
        return $order_ids;
    }

	public function _views(){
		$mdl_delivery = $this->app->model('business_goodscollection');
        $order_ids = $this->get_bo_ids();
        $sub_menu = array(
            0=>array('label'=>app::get('b2c')->_('未集货'),'optional'=>false,'filter'=>array('status'=>array('0'),'childOrder_id|in'=>$order_ids)),
            1=>array('label'=>app::get('b2c')->_('部分集货'),'optional'=>false,'filter'=>array('status'=>array('1'),'childOrder_id|in'=>$order_ids)),
            2=>array('label'=>app::get('b2c')->_('已集货'),'optional'=>false,'filter'=>array('status'=>array('2'))),
        );
        if(isset($_GET['optional_view'])) $sub_menu[$_GET['optional_view']]['optional'] = false;

        foreach($sub_menu as $k=>$v){
            if($v['optional']==false){
                $show_menu[$k] = $v;
                if(is_array($v['filter'])){
                    $v['filter'] = array_merge(array(),$v['filter']);
                }else{
                    $v['filter'] = array();
                }
                $show_menu[$k]['filter'] = $v['filter']?$v['filter']:null;
                if($k==$_GET['view']){
                    $show_menu[$k]['newcount'] = true;
                    $show_menu[$k]['addon'] = $mdl_delivery->count($v['filter']);
                }
                $show_menu[$k]['href'] = 'index.php?app=b2c&ctl=admin_operator_list&act=index&view='.($k).(isset($_GET['optional_view'])?'&optional_view='.$_GET['optional_view'].'&view_from=dashboard':'');
            }elseif(($_GET['view_from']=='dashboard')&&$k==$_GET['view']){
                $show_menu[$k] = $v;
            }
        }
        return $show_menu;
	}
}